package com.bzchao.oauth.controller;

import com.bzchao.oauth.bean.Dept;
import com.bzchao.oauth.bean.SysUser;
import com.bzchao.oauth.service.DeptService;
import com.bzchao.oauth.service.UserService;
import com.bzchao.oauth.service.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@PreAuthorize("permitAll")
@RequestMapping(value = "/test")
public class TestController {
    @Autowired
    private UserService userService;

    @PreAuthorize("permitAll")
    @RequestMapping
    public Object test() {
        System.out.println("test");
        return userService.selectUserByRoleId("4028a1cd4ee2d9d6014ee2df4c6a0007");
    }

    @RequestMapping(value = "/role")
    public Object role() {
        return userService.findByUsername("admin");
    }

    @RequestMapping(value = "/user")
    public Object user() {
        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }
}
